package uform.model.core;

class Filters<T>
{
	var _filters : Array<T -> T>;
	public function new()
	{
		_filters = [];
	}
	
	public function add(filter : T -> T)
	{
		_filters.push(filter);
	}
	
	public function remove(filter : T -> T)
	{
		for (i in 0..._filters.length)
		{
			if (Reflect.compareMethods(filter, _filters[i]))
			{
				_filters.splice(i, 1);
				return true;
			}
		}
		return false;
	}
	
	public function clear()
	{
		_filters = [];
	}
	
	public function filter(value : T)
	{
		for (f in _filters)
		{
			value = f(value);
		}
		return value;
	}
}